home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_110 / mint / bash110s.zoo / bash-1.10 / flags.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-04  |  6.1 KB  |  222 lines

  1. /* flags.c -- Everything about flags except the `set' command.  That
  2.    is in builtins.c */
  3.  
  4. /* Copyright (C) 1987,1989 Free Software Foundation, Inc.
  5.  
  6. This file is part of GNU Bash, the Bourne Again SHell.
  7.  
  8. Bash is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation; either version 1, or (at your option) any later
  11. version.
  12.  
  13. Bash is distributed in the hope that it will be useful, but WITHOUT ANY
  14. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License along
  19. with Bash; see the file COPYING.  If not, write to the Free Software
  20. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. /* Flags hacking. */
  23.  
  24. #include "config.h"
  25. #include "flags.h"
  26. #include "general.h"
  27. #include "quit.h"
  28.  
  29. /* **************************************************************** */
  30. /*                                    */
  31. /*            The Standard Sh Flags.                */
  32. /*                                    */
  33. /* **************************************************************** */
  34.  
  35. /* Non-zero means automatically mark variables which are modified or created
  36.    as auto export variables. */
  37. int mark_modified_vars = 0;
  38.  
  39. /* Non-zero means exit immediately if a command exits with a non-zero
  40.    exit status. */
  41. int exit_immediately_on_error = 0;
  42.  
  43. /* Non-zero means disable filename globbing. */
  44. int disallow_filename_globbing = 0;
  45.  
  46. /* Non-zero means to locate and remember function commands as functions are
  47.    defined.  Function commands are normally located when the function is
  48.    executed. */
  49. int locate_commands_in_functions = 0;
  50.  
  51. /* Non-zero means that all keyword arguments are placed into the environment
  52.    for a command, not just those that appear on the line before the command
  53.    name. */
  54. int place_keywords_in_env = 0;
  55.  
  56. /* Non-zero means read commands, but don't execute tham.  This is useful
  57.    for debugging shell scripts that should do something hairy and possibly
  58.    desctructive. */
  59. int read_but_dont_execute = 0;
  60.  
  61. /* Non-zero means end of file is after one command. */
  62. int just_one_command = 0;
  63.  
  64. /* Non-zero means don't overwrite existing files while doing redirections. */
  65. int noclobber = 0;
  66.  
  67. /* Non-zero means trying to get the value of $i where $i is undefined
  68.    causes an error, instead of a null substitution. */
  69. int unbound_vars_is_error = 0;
  70.  
  71. /* Non-zero means type out input lines after you read them. */
  72. int echo_input_at_read = 0;
  73.  
  74. /* Non-zero means type out the command definition after reading, but
  75.    before executing. */
  76. int echo_command_at_execute = 0;
  77.  
  78. /* Non-zero means turn off the job control features. */
  79. int jobs_m_flag = 0;
  80.  
  81. /* Non-zero means this shell is interactive, even if running under a
  82.    pipe. */
  83. int forced_interactive = 0;
  84.  
  85. /* **************************************************************** */
  86. /*                                    */
  87. /*             Non-Standard Flags Follow Here.            */
  88. /*                                    */
  89. /* **************************************************************** */
  90.  
  91.  
  92. /* Non-zero means do lexical scoping in the body of a FOR command. */
  93. int lexical_scoping = 0;
  94.  
  95. /* Non-zero means no such thing as invisible variables. */
  96. int no_invisible_vars = 0;
  97.  
  98. /* Non-zero means don't look up or remember command names in a hash table, */
  99. int hashing_disabled = 0;
  100.  
  101. /* Non-zero means that we are doing history expansion.  The default.
  102.    This means !22 gets the 22nd line of history. */
  103. int history_expansion = 1;
  104.  
  105. /* **************************************************************** */
  106. /*                                    */
  107. /*            The Flags ALIST.                */
  108. /*                                    */
  109. /* **************************************************************** */
  110.  
  111. struct flags_alist shell_flags[] = {
  112.  
  113.   /* Standard sh flags. */
  114.   { "a", &mark_modified_vars },
  115.   { "e", &exit_immediately_on_error },
  116.   { "f", &disallow_filename_globbing },
  117.   { "h", &locate_commands_in_functions }, /* Oh, yeah, good mnemonic. */
  118.   { "i", &forced_interactive },
  119.   { "k", &place_keywords_in_env },
  120.   { "n", &read_but_dont_execute },
  121.   { "t", &just_one_command },
  122.   { "u", &unbound_vars_is_error },
  123.   { "v", &echo_input_at_read },
  124.   { "x", &echo_command_at_execute },
  125.   { "C", &noclobber },
  126.  
  127. #if defined (JOB_CONTROL)
  128.   { "m", &jobs_m_flag },
  129. #endif
  130.  
  131.   /* New flags that control non-standard things. */
  132.   { "l", &lexical_scoping },
  133.   { "I", &no_invisible_vars },
  134.  
  135.   /* I want `h', but locate_commands_in_functions has it.  Great. */
  136.   { "d", &hashing_disabled },
  137.  
  138.   /* Once again, we don't have the right mnemonic. */
  139.   { "H", &history_expansion },
  140.  
  141.   {(char *)NULL, (int *)NULL}
  142. };
  143.  
  144.  
  145. int *
  146. find_flag (name)
  147.      char *name;
  148. {
  149.   int i = 0;
  150.   while (shell_flags[i].name) {
  151.     if (strcmp (shell_flags[i].name, name) == 0)
  152.       return (shell_flags[i].value);
  153.     i++;
  154.   }
  155.   return ((int *)FLAG_ERROR);
  156. }
  157.  
  158. /* Change the state of a flag, and return it's original value, or return
  159.    FLAG_ERROR if there is no flag called NAME.  ON_OR_OFF should be one
  160.    of FLAG_ON or FLAG_OFF. */
  161.  
  162. /* With FLAG being a character. */
  163. change_flag_char (flag, on_or_off)
  164.      int flag;
  165.      int on_or_off;
  166. {
  167.   char name[2];
  168.   name[0] = flag; name[1] = '\0';
  169.   return (change_flag (name, on_or_off));
  170. }
  171.  
  172. /* With FLAG being a string. */
  173. change_flag (flag, on_or_off)
  174.   char *flag;
  175.   int on_or_off;
  176. {
  177.   int *value = find_flag (flag);
  178.   int old_value;
  179.  
  180.   if (value == (int *)FLAG_ERROR) return (FLAG_ERROR);
  181.   else old_value = *value;
  182.  
  183.   if (on_or_off == FLAG_ON)
  184.     *value = 1;
  185.   else
  186.     {
  187.       if (on_or_off == FLAG_OFF)
  188.     *value = 0;
  189.       else
  190.     return (FLAG_ERROR);
  191.     }
  192.  
  193. #if defined (JOB_CONTROL)
  194.   /* Special hack for the -m flag. */
  195.   if (value == &jobs_m_flag)
  196.     {
  197.       extern set_job_control ();
  198.       set_job_control (on_or_off == '-');
  199.     }
  200. #endif /* JOB_CONTROL */
  201.     
  202.   return (old_value);
  203. }
  204.  
  205. /* Return a string which is the names of all the currently
  206.    set shell flags. */
  207. char *
  208. which_set_flags ()
  209. {
  210.   char *temp =
  211.     (char *)xmalloc (1 + sizeof (shell_flags) / (2 * sizeof (char *)));
  212.  
  213.   int index, string_index = 0;
  214.  
  215.   for (index = 0; shell_flags[index].name; index++)
  216.     if (*(shell_flags[index].value))
  217.       temp[string_index++] = *(shell_flags[index].name);
  218.  
  219.   temp[string_index] = '\0';
  220.   return (temp);
  221. }
  222.